package columnar;

import java.io.IOException;

import bitmap.*;

import java.util.*;
import java.lang.*;

import heap.*;
import bufmgr.*;
import diskmgr.*;
import global.*;
import chainexception.*;
import btree.*;

public class ColumnarFile implements GlobalConst {
	public static int count = 0;
	public String columnfileName;
	public int numColumns;
	Heapfile[] columnFiles;
	public AttrType[] attrtype;
	short sizeOfString = 32;
	private ArrayList<Integer> distinctList = new ArrayList<Integer>();
	private ArrayList<String> distinctStringList = new ArrayList<String>();

	private final static int reclen = 32;
	public BitSet deletedList = new BitSet();
	public int deleteListIndex;
	public int bitarrSize = 0;
	public String dbname;

	public ColumnarFile() {
	}

	public ColumnarFile(String name, int numCols, AttrType[] type) {
		int i = 0;
		this.dbname = "cdbname";
		this.columnfileName = name;
		this.numColumns = numCols;
		this.attrtype = type;

	}

	public void deleteColumnarFile() {
		int i;
		for (i = 0; i < this.numColumns; i++) {
			try {
				Heapfile hp = new Heapfile(this.columnfileName + i);
				hp.deleteFile();
			} catch (Exception e) {
			}
		}
	}

	public TID insertTuple(byte[] data) {
		RID rid;

		TID tid;
		int i = 0, j = 0;
		RID[] ridArr = new RID[this.numColumns];
		int offset = 0;
		int length = 0;
		offset = ((this.numColumns + 2) * 2);
		for (i = 0; i < this.numColumns; i++)

		{

			try {
				Tuple t = new Tuple();

				AttrType[] at = new AttrType[1];
				at[0] = new AttrType(this.attrtype[i].attrType);
				// at[1] = new AttrType(AttrType.attrInteger);
				short[] tsize = new short[1];

				if (this.attrtype[i].attrType == 0) {
					tsize[0] = strlen;
					length = strlen + 2;
				} else
					length = 4;

				t.setHdr((short) 1, at, tsize);
				// t.getStrFld(1,data[i]);

				Tuple tup = new Tuple(t.size());
				tup.setHdr((short) 1, at, tsize);

				// System.out.println("offset="+offset);
				// System.out.println("length="+length);

				if (this.attrtype[i].attrType == 0) {
					// System.out.println(Convert.getStrValue(offset,data,length));
					tup.setStrFld(1, Convert.getStrValue(offset, data, length));
				} else {
					// System.out.println(Convert.getIntValue(offset,data));
					tup.setIntFld(1, Convert.getIntValue(offset, data));
				}

				offset = offset + length;
				// t.tupleCopy(tup);
				Heapfile hf = new Heapfile(this.columnfileName + i);
				rid = hf.insertRecord(tup.returnTupleByteArray());

			//	tup = hf.getRecord(rid);

				// System.out.println(rid.pageNo);
				// System.out.println(rid.slotNo);
			//	t.tupleCopy(tup);

				/*
				 * if(this.attrtype[i].attrType==0)
				 * System.out.println(t.getStrFld(1)); else
				 * System.out.println(t.getIntFld(1));
				 */

				// System.out.println(tup.getStrFld(1));
				// System.out.println(tup.getIntFld(2));
				// hf.getRecord(rid).p
				// System.out.println("record count"+hf.getRecord(rid).);
				ridArr[i] = rid;

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}

	//this.deletedList.set(this.deleteListIndex++, true);
	//	this.bitarrSize = this.deletedList.length();
		//System.out.println(this.deletedList.length());
		// byte[] bArr = convertToByteArray(deletedList, 1);
		// BitSet bSet = fromByteArray(bArr);
		/*
		for (int z = 0; z < this.deletedList.length(); z++) {
			if (this.deletedList.get(z) == true)
				System.out.print(1);
			else
				System.out.print(0);
		}*/
		System.out.println("");
		tid = new TID(this.numColumns, count, ridArr);
		// this.tidArr[count] = tid;
		// getTuple(tid);
		count++;
		// tid.writeToByteArray(, offset)
		return tid;
	}

	public Tuple getTuple(TID tid) throws Exception {

		int i = 0;
		Tuple t = new Tuple();
		int k = 0;

		for (AttrType at : this.attrtype) {
			if (at.attrType == 0)
				k++;
		}
		short[] tsize = new short[k];
		for (int l = 0; l < k; l++) {
			tsize[l] = strlen;
		}
		short num = (short) this.numColumns;
		t.setHdr(num, this.attrtype, tsize);
		Tuple tup = new Tuple(t.size());
		tup.setHdr(num, this.attrtype, tsize);
		try {

			for (i = 0; i < tid.recordIDs.length; i++) {

				Tuple t1 = new Tuple();
				AttrType[] at = new AttrType[1];
				at[0] = new AttrType(this.attrtype[i].attrType);
				// at[1] = new AttrType(AttrType.attrInteger);
				short[] tsize1 = new short[1];

				if (this.attrtype[i].attrType == 0) {
					tsize1[0] = strlen;

				}

				t1.setHdr((short) 1, at, tsize1);
				// t.getStrFld(1,data[i]);

				Tuple tup1 = new Tuple(t1.size());
				tup1.setHdr((short) 1, at, tsize1);
				Heapfile hf = new Heapfile(this.columnfileName + i);
				tup1 = hf.getRecord(tid.recordIDs[i]);
				t1.tupleCopy(tup1);

				if (this.attrtype[i].attrType == 0) {
					tup.setStrFld(i + 1, t1.getStrFld(1));
					// System.out.println("from gettuple:"+t1.getStrFld(1));
				} else {
					tup.setIntFld(i + 1, t1.getIntFld(1));
					// System.out.println("from gettuple:"+t1.getIntFld(1));
				}

			}
		} catch (Exception e) {

		}

		return tup;
	}

	public String getValue(TID tid, int column) {
		String value = "";
		try {
			int i;

			Tuple t1 = new Tuple();
			AttrType[] at = new AttrType[1];
			at[0] = new AttrType(this.attrtype[column - 1].attrType);
			// at[1] = new AttrType(AttrType.attrInteger);
			short[] tsize1 = new short[1];

			if (this.attrtype[column - 1].attrType == 0) {
				tsize1[0] = strlen;

			}

			t1.setHdr((short) 1, at, tsize1);
			// t.getStrFld(1,data[i]);

			Tuple tup1 = new Tuple(t1.size());
			tup1.setHdr((short) 1, at, tsize1);
			Heapfile hf = new Heapfile(this.columnfileName + (column - 1));
			tup1 = hf.getRecord(tid.recordIDs[column - 1]);
			t1.tupleCopy(tup1);

			if (this.attrtype[column - 1].attrType == 0) {
				value = t1.getStrFld(1);
				System.out.println("from gettuple:" + t1.getStrFld(1));
			} else {
				// tup.setIntFld(i+1, t1.getIntFld(1));
				System.out.println("from gettuple:" + t1.getIntFld(1));
			}

		} catch (Exception e) {

		}
		return value;
	}

	public int getTupleCnt() {
		return 1;
	}

	public TupleScan openTupleScan(int[] targetcolno) throws InvalidTupleSizeException,
			IOException {
		TupleScan sc = null;
		try {
			sc = new TupleScan(this,targetcolno);
		} catch (Exception e) {
		}
		return sc;
	}

	public Scan openColumnScan(int columnNo) throws InvalidTupleSizeException,
			IOException, HFDiskMgrException, HFBufMgrException, HFException {
		Heapfile hf = new Heapfile(this.columnfileName + (columnNo - 1));
		Scan newscan = new Scan(hf);
		return newscan;
	}

	public boolean updateTuple(TID tid, Tuple newtuple)
			throws InvalidSlotNumberException, InvalidUpdateException,
			InvalidTupleSizeException, HFException, HFDiskMgrException,
			HFBufMgrException, Exception {
		boolean result = true;
		Tuple tup = new Tuple();
		int k = 0;
		for (AttrType at : this.attrtype) {
			if (at.attrType == 0)
				k++;
		}
		short[] tsize = new short[k];
		for (int l = 0; l < k; l++) {
			tsize[l] = strlen;
		}
		short num = (short) this.numColumns;
		tup.setHdr(num, this.attrtype, tsize);
		Tuple t = new Tuple(tup.size());
		t.setHdr(num, this.attrtype, tsize);
		t.tupleCopy(newtuple);
		for (int y = 0; y < this.numColumns; y++) {
			if (this.attrtype[y].attrType == 0) {
				Tuple t1 = new Tuple();
				AttrType[] at = new AttrType[1];
				at[0] = new AttrType(this.attrtype[y].attrType);
				// at[1] = new AttrType(AttrType.attrInteger);
				short[] tsize1 = new short[1];

				if (this.attrtype[y].attrType == 0) {
					tsize1[0] = strlen;

				}

				t1.setHdr((short) 1, at, tsize1);
				// t.getStrFld(1,data[i]);

				Tuple tup1 = new Tuple(t1.size());
				tup1.setHdr((short) 1, at, tsize1);
				tup1.setStrFld(1, t.getStrFld(y + 1));

				Heapfile hf = new Heapfile(this.columnfileName + y);
				result = hf.updateRecord(tid.recordIDs[y], tup1);

			} else {
				Tuple t1 = new Tuple();
				AttrType[] at = new AttrType[1];
				at[0] = new AttrType(this.attrtype[y].attrType);
				// at[1] = new AttrType(AttrType.attrInteger);
				short[] tsize1 = new short[1];

				t1.setHdr((short) 1, at, tsize1);
				// t.getStrFld(1,data[i]);

				Tuple tup1 = new Tuple(t1.size());
				tup1.setHdr((short) 1, at, tsize1);
				tup1.setIntFld(1, t.getIntFld(y + 1));

				Heapfile hf = new Heapfile(this.columnfileName + y);
				result = hf.updateRecord(tid.recordIDs[y], tup1);

			}
			if (result == false)
				break;
			else
				continue;
		}
		return result;
	}

	public boolean updateColumnofTuple(TID tid, Tuple newtuple, int column)
			throws InvalidSlotNumberException, InvalidUpdateException,
			InvalidTupleSizeException, HFException, HFDiskMgrException,
			HFBufMgrException, Exception {
		boolean result = true;
		Tuple tup = new Tuple();
		int k = 0;
		for (AttrType at : this.attrtype) {
			if (at.attrType == 0)
				k++;
		}
		short[] tsize = new short[k];
		for (int l = 0; l < k; l++) {
			tsize[l] = strlen;
		}
		short num = (short) this.numColumns;
		tup.setHdr(num, this.attrtype, tsize);
		Tuple t = new Tuple(tup.size());
		t.setHdr(num, this.attrtype, tsize);
		t.tupleCopy(newtuple);

		if (this.attrtype[column - 1].attrType == 0) {
			Tuple t1 = new Tuple();
			AttrType[] at = new AttrType[1];
			at[0] = new AttrType(this.attrtype[column - 1].attrType);
			// at[1] = new AttrType(AttrType.attrInteger);
			short[] tsize1 = new short[1];

			if (this.attrtype[column - 1].attrType == 0) {
				tsize1[0] = strlen;

			}

			t1.setHdr((short) 1, at, tsize1);
			// t.getStrFld(1,data[i]);

			Tuple tup1 = new Tuple(t1.size());
			tup1.setHdr((short) 1, at, tsize1);
			tup1.setStrFld(1, t.getStrFld(column));

			Heapfile hf = new Heapfile(this.columnfileName + (column - 1));
			result = hf.updateRecord(tid.recordIDs[column - 1], tup1);

		} else {
			Tuple t1 = new Tuple();
			AttrType[] at = new AttrType[1];
			at[0] = new AttrType(this.attrtype[column - 1].attrType);
			// at[1] = new AttrType(AttrType.attrInteger);
			short[] tsize1 = new short[1];

			t1.setHdr((short) 1, at, tsize1);
			// t.getStrFld(1,data[i]);

			Tuple tup1 = new Tuple(t1.size());
			tup1.setHdr((short) 1, at, tsize1);
			tup1.setIntFld(1, t.getIntFld(column));

			Heapfile hf = new Heapfile(this.columnfileName + (column - 1));
			result = hf.updateRecord(tid.recordIDs[column - 1], tup1);
		}

		return result;
	}

	/*
	 * public boolean createBTreeIndex(int column) {
	 * 
	 * }
	 */

	/**
	 * 
	 * @param column
	 * @return
	 * @throws IOException
	 * @throws HFDiskMgrException
	 * @throws HFBufMgrException
	 * @throws HFException
	 */

	public boolean createBTreeIndex(String filename, int column, int type)
			throws HFException, HFBufMgrException, HFDiskMgrException,
			IOException {

		BTreeFile btreeFile = null;
		int tempnum = column - 1;
		String Btreefile = "Btree" + filename + tempnum;
		int keyType = type;/* this.attrtype[column-1].attrType; */
		int deleteFashion = 0; // Naive delete

		int keySize = 0;
		if (/* this.attrtype[column-1].attrType */type == AttrType.attrInteger) {
			keySize = 4;
		} else if (/* this.attrtype[column-1].attrType */type == AttrType.attrString) {
			keySize = sizeOfString;
		}

		try {
			btreeFile = new BTreeFile(Btreefile, keyType, keySize,
					deleteFashion);
		} catch (Exception e) {
			e.printStackTrace();
			Runtime.getRuntime().exit(1);
		}
		System.out.println("BTreeIndex created successfully.\n");

		Heapfile columnHeapfile = new Heapfile(this.columnfileName
				+ (column - 1));

		Scan scan = null;

		try {
			scan = new Scan(columnHeapfile);
		} catch (Exception e) {
			e.printStackTrace();
			Runtime.getRuntime().exit(1);
		}

		RID rid = new RID();

		Tuple temp = null;
		Tuple t = new Tuple();
		short[] strSizes = new short[1];
		strSizes[0] = sizeOfString;
		AttrType[] types = new AttrType[1];

		try {
			temp = scan.getNext(rid);

			if (keyType == AttrType.attrInteger) {

				types[0] = new AttrType(AttrType.attrInteger);
				t.setHdr((short) 1, types, strSizes);
				int key = -1;
				while (temp != null) {
					t.tupleCopy(temp);

					try {
						key = t.getIntFld(1);
					} catch (Exception e) {
						e.printStackTrace();
					}

					try {
						btreeFile.insert(new IntegerKey(key), rid);
					} catch (Exception e) {

						e.printStackTrace();
					}

					try {
						temp = scan.getNext(rid);
					} catch (Exception e) {

						e.printStackTrace();
					}
				}

			} else if (keyType == AttrType.attrString) {

				types[0] = new AttrType(AttrType.attrString);
				t.setHdr((short) 1, types, strSizes);
				String key = null;
				while (temp != null) {
					t.tupleCopy(temp);

					try {
						key = t.getStrFld(1);
					} catch (Exception e) {
						e.printStackTrace();
					}

					try {
						btreeFile.insert(new StringKey(key), rid);
					} catch (Exception e) {

						e.printStackTrace();
					}

					try {
						temp = scan.getNext(rid);
					} catch (Exception e) {

						e.printStackTrace();
					}
				}
			}

			BTFileScan btFileScan = btreeFile.new_scan(null, null);
			KeyDataEntry entry = btFileScan.get_next();

			while (entry != null) {

				if (entry.data instanceof LeafData) {

					System.out.println("Btree Data:" + entry.key);

					RID ridTemp = new RID();
					ridTemp.slotNo = ((LeafData) entry.data).getData().slotNo;
					ridTemp.pageNo = ((LeafData) entry.data).getData().pageNo;
					System.out.println(ridTemp.slotNo);// + ridTemp.pageNo);
					System.out.println(ridTemp.pageNo);
				}

				entry = btFileScan.get_next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}

	public boolean markTupleDeleted(TID tid) {
		boolean result = true;
		try {
			this.deletedList.set(tid.position, false);
			System.out.println(this.deletedList.length());
			for (int z = 0; z < this.bitarrSize; z++) {
				if (this.deletedList.get(z) == true)
					System.out.print(1);
				else
					System.out.print(0);
			}
			System.out.println(this.deletedList.length());
			System.out.println("");
		} catch (Exception e) {
		}
		return result;
	}

	public boolean purgeAllDeletedTuples() {
		boolean result = true;
		int position = -1;

		try {
			for (int y = 0; y < this.numColumns; y++) {
				position = 0;
				Heapfile hf = new Heapfile(this.columnfileName + y);
				Scan sc = new Scan(hf);
				RID rid = new RID();
				// System.out.println(hf.getRecCnt());
				do {
					sc.getNext(rid);
					System.out.println("rid details:" + rid.pageNo + ","
							+ rid.slotNo);
					position++;

				} while (position != hf.getRecCnt());

			}
			// deletedList.set(tid.position, false);
			System.out.println(this.deletedList.length());
			for (int z = 0; z < this.bitarrSize - 1; z++) {
				if (this.deletedList.get(z) == false) {
					for (int y = 0; y < this.numColumns; y++) {
						position = -1;
						Heapfile hf = new Heapfile(this.columnfileName + y);
						Scan sc = new Scan(hf);
						RID rid = new RID();
						// System.out.println(hf.getRecCnt());
						do {
							sc.getNext(rid);
							position++;
						} while (position != z);
						hf.deleteRecord(rid);
						System.out.println("heapfile," + y + ",count:"
								+ hf.getRecCnt());
						position = 0;
						Heapfile hf1 = new Heapfile(this.columnfileName + y);
						Scan sc1 = new Scan(hf);
						RID rid1 = new RID();
						do {

							sc1.getNext(rid1);
							System.out.println("rid details:" + rid1.pageNo
									+ "," + rid1.slotNo);
							position++;

						} while (position != hf1.getRecCnt());
					}
				}
			}
			System.out.println("now after delete");
			for (int y = 0; y < this.numColumns; y++) {
				position = 0;
				Heapfile hf = new Heapfile(this.columnfileName + y);
				Scan sc = new Scan(hf);
				RID rid = new RID();
				// System.out.println(hf.getRecCnt());
				do {
					sc.getNext(rid);
					System.out.println("rid details:" + rid.pageNo + ","
							+ rid.slotNo);
					position++;

				} while (position != hf.getRecCnt());

			}
			System.out.println("");
		} catch (Exception e) {
		}
		return result;

	}

	public boolean createBitMapIndex(int columnno, String dbName, String value) throws IteratorException, ConstructPageException, PinPageException, UnpinPageException, IOException{

	    BitMapFile bitMapFile;
	    
	  int keyType = this.attrtype[columnno-1].attrType;
	  int keySize = 0;
	  
	    String fileName = "BitMapIndex_" + String.valueOf(columnno) + "_" + value.toString();
	    System.out.println(fileName);
	    try{
	    	Heapfile columnHeap = new Heapfile(this.columnfileName+(columnno-1));
	        bitMapFile = new BitMapFile(fileName);
	        System.out.println("BitMap Index created successfully");

	        // Setting up the scan
	        Scan scan = null;

	        try{
	            scan = new Scan(columnHeap);
	        }catch(Exception ex){
	            ex.printStackTrace();
	            Runtime.getRuntime().exit(1);
	        }

	        RID rid = new RID();

	        Tuple temp = null;
	        Tuple t = new Tuple();
	        short[] strSizes = new short[1];       
	        AttrType[] types = new AttrType[1];

	        //Scanning through the heap file and inserting the records.
	        try{
	            temp = scan.getNext(rid);

	            if(keyType == AttrType.attrInteger){

	                types[0] = new AttrType(AttrType.attrInteger);
	                t.setHdr((short)1, types, strSizes);
	                int key = -1; 
	                while (temp != null) {
	                    t.tupleCopy(temp);

	                    try {
	                        key = t.getIntFld(1);
	                    } catch (Exception e) {
	                        e.printStackTrace();
	                    }

	                    try {                                                                   
	                           
	                        if(Integer.parseInt(value) == key){
	                                bitMapFile.insert(new Boolean(true));
	                                
	                            }else{
	                                bitMapFile.insert(new Boolean(false));
	                            }
	                    } catch (Exception e) {

	                        e.printStackTrace();
	                    }

	                    try {
	                        temp = scan.getNext(rid);
	                    } catch (Exception e) {

	                        e.printStackTrace();
	                    }
	                }
	                
	                try{
	                    bitMapFile.convertBitSetIntoByteStream();
	                }catch (Exception e) {
	                    e.printStackTrace();
	                    Runtime.getRuntime().exit(1);
	                }

	                // Writing into the Bitmap data pages
	                try{
	                     bitMapFile.writeIntoDataPages();
	                  //  System.out.println("Return Value of write into data pages " + returnValue);
	                }catch (Exception e) {
	                    e.printStackTrace();
	                    Runtime.getRuntime().exit(1);
	                }


	            }
	            else if (keyType == AttrType.attrString){
	            	
	            	System.out.println("Creation of Bitmap for Ist Distinct Value:" + value);
	            	strSizes[0] = sizeOfString;
	                types[0] = new AttrType(AttrType.attrString);
	               
	                t.setHdr((short)1, types, strSizes);
	                String key = null; 
	                while (temp != null) {
	                    t.tupleCopy(temp);

	                    try {
	                        key = t.getStrFld(1);
	                    } catch (Exception e) {
	                        e.printStackTrace();
	                    }

	                    try {

	                        //String strValue = new String("ABCD 123");
	                        if(value.equalsIgnoreCase(key)){
	                       
	                            bitMapFile.insert(new Boolean(true));                            
	                        }
	                        else{                     
	                        	bitMapFile.insert(false);
	                        }
	                    } catch (Exception e) {

	                        e.printStackTrace();
	                    }

	                    try {
	                        temp = scan.getNext(rid);
	                    } catch (Exception e) {

	                        e.printStackTrace();
	                    }
	                }
	                
	                
	                try{
	                    bitMapFile.convertBitSetIntoByteStream();
	                }catch (Exception e) {
	                    e.printStackTrace();
	                    Runtime.getRuntime().exit(1);
	                }

	                // Writing into the Bitmap data pages
	                try{
	                    bitMapFile.writeIntoDataPages();
	                }catch (Exception e) {
	                    e.printStackTrace();
	                    Runtime.getRuntime().exit(1);
	                }
	            }
	            
//	            bitMapFile = new BitMapFile(fileName);
//	            if (bitMapFile )

	        }catch(Exception ex){
	            ex.printStackTrace();
	            Runtime.getRuntime().exit(1);
	        }
	        
	        // Initiating Bit map Scan
	        
	        BMFileScan bitmapFileScan = bitMapFile.new_scan();
	        
	        KeyDataEntry key;
	        key = bitmapFileScan.get_next();
	        int position = key.position;
	        
	        // -1 indicates the end of the file
	        while(position != -1){
	        	key = bitmapFileScan.get_next();
		        position = key.position;
	        }
	        
	        bitMapFile.close();
	    }catch(Exception ex){
	        ex.printStackTrace();
	        Runtime.getRuntime().exit(1);
	    }

	    return true;
	}

	public void findDistinctValues(int columnNum, int type)
	throws  IOException, Exception {

	RID rid = new RID();
	Heapfile hf = new Heapfile(this.columnfileName+(columnNum-1));
	Scan sc = new Scan(hf);
	String cdbname = "/tmp/"+ this.dbname;
	System.out.println(hf.getRecCnt());
	for (int i=0 ; i<hf.getRecCnt();i++)
	{
		if(this.attrtype[columnNum-1].attrType==0)
		{		
			Tuple t1 = new Tuple();
			AttrType[] at = new AttrType[1];
			at[0] = new AttrType(AttrType.attrString);
			short[] tsize1 = new short[1];
			tsize1[0] = strlen;
			t1.setHdr((short) 1, at, tsize1);		
		    Tuple tup1 = new Tuple(t1.size());
		    tup1.setHdr((short) 1, at, tsize1);
			tup1= sc.getNext(rid);
			t1.tupleCopy(tup1);
			String distVal = t1.getStrFld(1);
			
		if (!distinctStringList.contains(distVal)) {
			distinctStringList.add(distVal);
		}else{
			System.out.println("Already present in the Distinct List!");
		}
			
		}
		else
		{
			Tuple t1 = new Tuple();
			AttrType[] at = new AttrType[1];	
			at[0] = new AttrType(AttrType.attrInteger);
			short[] tsize1 = new short[1];		
			t1.setHdr((short) 1, at, tsize1);	
			
		    Tuple tup1 = new Tuple(t1.size());
		    tup1.setHdr((short) 1, at, tsize1);
			tup1= sc.getNext(rid);
			t1.tupleCopy(tup1);
			int distVal = t1.getIntFld(1);
			
		if (!distinctList.contains(new Integer(distVal))) {
			distinctList.add(new Integer(distVal));								
		}else{
			System.out.println("Already Present in the Distinct list!");
		}
		}
		
		
		
	}		
	if(this.attrtype[columnNum-1].attrType==0)
	{
			for (int i=0; i<distinctStringList.size();i++){		
				System.out.println(distinctStringList.get(i));
				createBitMapIndex(columnNum, cdbname, distinctStringList.get(i));
			}
			}
	else{
				for (int i=0; i<distinctList.size();i++) {
				System.out.println(distinctList.get(i));
				createBitMapIndex(columnNum, cdbname, distinctList.get(i).toString());
				}
			}

		}	
	}
/*
 * public boolean createBitMapIndex(int columnNo, ValueClass value) {
 * 
 * }
 * 
 * public boolean markTupleDeleted(TID tid) {
 * 
 * }
 * 
 * public boolean purgeAllDeletedTuples() {
 * 
 * }
 * 
 * }
 */